package mt.filter.clock;

import java.util.ArrayList;
import java.util.List;

public class SystemClock extends Thread implements Clock{
	private double tick = 0;
	private List<ClockAware> clockAwareList = new ArrayList<ClockAware>();
	
	@Override
	public void addClockAware(ClockAware clockAware) {
		this.clockAwareList.add(clockAware);
	}
	
	@Override
	public double getTime() {
		return tick;
	} 

	public void run(){
		try {
			while(true){
				sleep(1000);
				tick++;
				for(ClockAware clockAware : clockAwareList){
					clockAware.tick();
				}
			}
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	
}
